//
//  FXCNewsCell.m
//  XinLangFeiBo
//
//  Created by dllo on 16/3/3.
//  Copyright © 2016年 dllo. All rights reserved.
//

#import "FXCNewsCell.h"

@interface FXCNewsCell ()





@end


@implementation FXCNewsCell

- (instancetype)initWithStyle:(UITableViewCellStyle)style reuseIdentifier:(NSString *)reuseIdentifier{
    if (self = [super initWithStyle:style reuseIdentifier:reuseIdentifier]) {
        [self setUpSubviews];
    }
    return self;
}

- (void)setUpSubviews{
    _imageIcon = [[UIImageView alloc] init];
    [self.contentView addSubview:_imageIcon];
    
    _labelTitle = [[UILabel alloc] init];
    [self.contentView addSubview:_labelTitle];
    
    _subTitle = [[UILabel alloc] init];
    _subTitle.numberOfLines = 0;
    _subTitle.font = [UIFont systemFontOfSize:14];
    [self.contentView addSubview:_subTitle];
    
    _labelReply = [[UILabel alloc] init];
    _labelReply.font = [UIFont systemFontOfSize:12];
    [self.contentView addSubview:_labelReply];
    
    _image2 = [[UIImageView alloc] init];
    [self.contentView addSubview:_image2];
//    _image2.center = CGPointMake(self.contentView.centerX, self.contentView.centerY + 35);
    
    _image3 = [[UIImageView alloc] init];
    [self.contentView addSubview:_image3];
    
    
//    _imageIcon.frame = CGRectMake(0, 0, 60, 80);
//    _imageIcon.backgroundColor = [UIColor redColor];
//    
//    _labelTitle.frame = CGRectMake(80, 0, 60, 30);
    
//    _subTitle.frame = CGRectMake(80, 50, 60, 30);
//    _labelReply.frame = CGRectMake(200, 50, 30, 20);
//    _image2.frame = CGRectMake(1, 1, 1, 1);
    
}




- (void)setNewsModel:(FXCNewsModel *)newsModel{
    _newsModel = newsModel;
    
    [self.imageIcon sd_setImageWithURL:[NSURL URLWithString:self.newsModel.imgsrc] placeholderImage:[UIImage imageNamed:@"0"]];
    self.labelTitle.text = self.newsModel.title;
    self.subTitle.text = self.newsModel.digest;
    
    // 如果回复太多就改成几点几万
    CGFloat count =  [self.newsModel.replyCount intValue];
    NSString *displayCount;
    if (count > 10000) {
        displayCount = [NSString stringWithFormat:@"%.1f万跟帖",count/10000];
    }else{
        displayCount = [NSString stringWithFormat:@"%.0f跟帖",count];
    }
    self.labelReply.text = displayCount;
    
    // 多图cell
    if (self.newsModel.imgextra.count == 2) {
        
        //        [self.imgOther1 sd_setImageWithURL:[NSURL URLWithString:self.NewsModel.imgextra[0][@"imgsrc"]]];
        //        [self.imgOther2 sd_setImageWithURL:[NSURL URLWithString:self.NewsModel.imgextra[1][@"imgsrc"]]];
        
        [self.image2 sd_setImageWithURL:[NSURL URLWithString:self.newsModel.imgextra[0][@"imgsrc"]] placeholderImage:[UIImage imageNamed:@"302"]];
        [self.image3 sd_setImageWithURL:[NSURL URLWithString:self.newsModel.imgextra[1][@"imgsrc"]] placeholderImage:[UIImage imageNamed:@"302"]];
    }

    if (newsModel.hasHead && newsModel.photosetID) {
        _imageIcon.sd_layout
        .topSpaceToView(self.contentView, 0)
        .leftSpaceToView(self.contentView, 0)
        .rightSpaceToView(self.contentView, 0)
        .heightIs(200);
        
        
        _labelTitle.sd_layout
        .topSpaceToView(_imageIcon, 0)
        .leftEqualToView(_imageIcon)
        .widthIs(FXCScreenW - 100)
        .bottomSpaceToView(self.contentView, 0);
        
    }else if (newsModel.hasHead){
        _imageIcon.sd_layout
        .topSpaceToView(self.contentView, 0)
        .leftSpaceToView(self.contentView, 0)
        .rightSpaceToView(self.contentView, 0)
        .heightIs(200);
        
        
        _labelTitle.sd_layout
        .topSpaceToView(_imageIcon, 0)
        .leftEqualToView(_imageIcon)
        .widthIs(FXCScreenW - 100)
        .bottomSpaceToView(self.contentView, 0);
        
        
        
        
//        NSLog(@"!!!!!!!!!!!!!!!");
    }else if (newsModel.imgType){
        
        _labelTitle.sd_layout
        .topSpaceToView(self.contentView, 5)
        .leftSpaceToView(self.contentView, 5)
        .heightIs(20)
        .widthIs(FXCScreenW - 100);
        
        _imageIcon.sd_layout
        .topSpaceToView(_labelTitle, 5)
        .leftSpaceToView(self.contentView, 5)
        .rightSpaceToView(self.contentView, 5)
        .heightIs(100);
        
        _subTitle.sd_layout
        .topSpaceToView(_imageIcon, 5)
        .leftSpaceToView(self.contentView, 5)
        .widthIs(FXCScreenW - 100)
        .bottomSpaceToView(self.contentView, 5);
        
    }else if (newsModel.imgextra){
        
        
        _labelTitle.sd_layout
        .topSpaceToView(self.contentView, 5)
        .leftSpaceToView(self.contentView, 5)
        .heightIs(20)
        .widthIs(FXCScreenW - 100);
        
        _imageIcon.sd_layout
        .topSpaceToView(_labelTitle, 5)
        .leftSpaceToView(self.contentView, 5)
        .bottomSpaceToView(self.contentView, 5)
        .widthIs(FXCScreenW / 3 - 10);
        
        _image2.sd_layout
        .topSpaceToView(_labelTitle, 5)
        .leftSpaceToView(_imageIcon, 10)
        .bottomSpaceToView(self.contentView, 5)
        .widthIs(FXCScreenW / 3 - 10);

        
        _image3.sd_layout
        .topSpaceToView(_labelTitle, 5)
        .widthIs(FXCScreenW / 3 - 10)
        .bottomSpaceToView(self.contentView, 5)
        .rightSpaceToView(self.contentView, 5);
        
        _labelReply.sd_layout
        .topSpaceToView(self.contentView, 5)
        .heightIs(8)
        .widthIs(80)
        .rightSpaceToView(self.contentView, 5);
        
        
    }else{
        _imageIcon.sd_layout
        .topSpaceToView(self.contentView, 5)
        .leftSpaceToView(self.contentView, 5)
        .bottomSpaceToView(self.contentView, 5)
        .widthIs(60);
        
        _labelTitle.sd_layout
        .topSpaceToView(self.contentView, 5)
        .leftSpaceToView(_imageIcon, 5)
        .widthIs(FXCScreenW - 100)
        .heightIs(20);
        
        _subTitle.sd_layout
        .topSpaceToView(_labelTitle, 10)
        .leftSpaceToView(_imageIcon, 5)
        .widthIs(FXCScreenW - 100)
        .autoHeightRatio(0);
        
        
        _labelReply.sd_layout
        .rightSpaceToView(self.contentView, 5)
        .bottomSpaceToView(self.contentView, 5)
        .widthIs(80)
        .heightIs(8);
    }
    
}
+ (NSString *)idForRow:(FXCNewsModel *)NewsModel
{
    if (NewsModel.hasHead && NewsModel.photosetID) {
        return @"TopImageCell";
    }else if (NewsModel.hasHead){
        return @"TopTxtCell";
    }else if (NewsModel.imgType){
        return @"BigImageCell";
    }else if (NewsModel.imgextra){
        return @"ImagesCell";
    }else{
        return @"NewsCell";
    }
}
+ (CGFloat)heightForRow:(FXCNewsModel *)NewsModel
{
    if (NewsModel.hasHead && NewsModel.photosetID){
        return 245;
    }else if(NewsModel.hasHead) {
        return 245;
    }else if(NewsModel.imgType) {
        return 170;
    }else if (NewsModel.imgextra){
        return 130;
    }else{
        return 80;
    }
}
@end
